#include "image_remover.hpp"

ImageRemover::ImageRemover() noexcept
  : max_image_width_{0}
  , max_image_height_{0}
{ }



ImageRemover::ImageRemover(std::size_t max_image_width, std::size_t max_image_height) noexcept
  : max_image_width_{max_image_width}
  , max_image_height_{max_image_height}
{ }



void ImageRemover::start_removing(const std::vector<std::filesystem::path>& images_to_remove)
{
  if (!images_to_remove.empty())
  {
    sf::Image image{}; // Store image here
    for (auto&& filename : images_to_remove)
    {
      image.loadFromFile(filename.string());

      if (need_to_remove(image))
      {
        std::error_code remove_failed{}; // required to call noexcept func
        std::filesystem::remove(filename, remove_failed);
      }
    }
  }
}



bool ImageRemover::need_to_remove(const sf::Image& img) noexcept
{
  const auto [image_width, image_height]{img.getSize()};
  return (image_width < max_image_width_ && image_height < max_image_height_);
}
